<?php

/**
 * @author Martin Pernica
 * @copyright 2008 - 2009
 */

echo '<br /><h2><a href="index.php?p=components&name=custom">'.Lang::getBackGlobal('back').'</a></h2><br />';
 
if(!empty($_POST['title']) && !empty($_POST['page_content'])){

	$title = Registry::get('db')->real_escape_string(strip_tags($_POST['title']));
	$content = Registry::get('db')->real_escape_string($_POST['page_content']);
	$require_rank = intval($_POST['require_rank']);
	

	$query = Registry::get('db')->query("UPDATE {prefix}custom SET title = '".$title."', content = '".$content."', require_rank = '".$require_rank."' WHERE id = '".intval($_GET['id'])."'");
	$log->write(8, 'com_custom', 'NOW()', 'User edited page #'.intval($_GET['id']), User::getUid());
    
	messageBox( Lang::getBack('com_custom', 'edited_done') );
}

$query = Registry::get('db')->query("SELECT * FROM {prefix}custom WHERE id = '".intval($_GET['id'])."'");
$data = $query->fetch_array();

$form = new Form;
$form->addTextbox('title', Lang::getBack('com_custom', 'title'), stripslashes($data['title']));
$form->addTextarea('page_content', Lang::getBack('com_custom', 'content'), stripslashes($data['content']), 30, 80, 'wysiwyg');
$form->addSelect('require_rank', Lang::getBack('com_custom', 'permissions'), $ranks, $data['require_rank']);
$form->addSubmit('submit_edit', Lang::getBackGlobal('submit'));

echo $form;

?>